package com.pmcc.core.entity.security;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.pmcc.core.enums.EmpType;
import io.swagger.annotations.ApiModel;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@Entity
@Table(name = "SYS_EMPLOYEE")
@ApiModel
public class Employee extends Authenticatable implements Serializable {

    @Column(name = "USERNAME", length = 50, unique = true)
    private String username;

    @Column(name = "USER_CNAME", length = 100)
    private String userCName;//用户中文名

    @Column(name = "avatar", length = 200)
    private String avatar;//头像

    @Column(name = "address", length = 50)
    private String address;

    @Column(name = "MOBILE", length = 20)
    private String mobile;//手机号

    @Column(name = "EMAIL", length = 100)
    private String email;//EMAIL//

    @Enumerated(EnumType.STRING)
    @Column(name = "TYPE", length = 20)
    private EmpType type;//账号类型

    @Column(name = "SORT_NO", length = 11)
    private String sortNo;//排序

    @ManyToMany( fetch = FetchType.EAGER)//employee和role没有级联关系。不会同时新增或者删除。  所以这里级联关系为默认值无。
    @JoinTable(
            name = "SYS_EMPLOYEE_ROLE",
            joinColumns = {@JoinColumn(name = "EMPLOYEE_ID", referencedColumnName = "ID")},
            inverseJoinColumns = {@JoinColumn(name = "ROLE_ID", referencedColumnName = "ID")})
    private List<Role> roleList = new ArrayList<>();

    @JsonIgnore
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "ORG_ID")
    private Organization organization;

    public Employee() {
    }
}